import request from './request'

/**
 * 获取组织树
 */
export const getOrganizationTree = () => {
  return request({
    url: '/organization/tree',
    method: 'get'
  })
}

/**
 * 根据父ID获取子组织列表
 */
export const getOrganizationsByParentId = (parentId) => {
  return request({
    url: `/organization/children/${parentId}`,
    method: 'get'
  })
}

/**
 * 根据ID获取组织详情
 */
export const getOrganizationById = (id) => {
  return request({
    url: `/organization/${id}`,
    method: 'get'
  })
}

/**
 * 创建组织
 */
export const createOrganization = (data) => {
  return request({
    url: '/organization/create',
    method: 'post',
    data
  })
}

/**
 * 更新组织
 */
export const updateOrganization = (data) => {
  return request({
    url: '/organization/update',
    method: 'put',
    data
  })
}

/**
 * 删除组织
 */
export const deleteOrganization = (id) => {
  return request({
    url: `/organization/delete/${id}`,
    method: 'delete'
  })
}

/**
 * 获取组织成员列表
 */
export const getOrganizationMembers = (orgId) => {
  return request({
    url: `/organization/members/${orgId}`,
    method: 'get'
  })
}

/**
 * 添加组织成员
 */
export const addOrganizationMember = (data) => {
  return request({
    url: '/organization/member/add',
    method: 'post',
    data
  })
}

/**
 * 移除组织成员
 */
export const removeOrganizationMember = (userId, orgId) => {
  return request({
    url: `/organization/member/remove/${userId}/${orgId}`,
    method: 'delete'
  })
}

/**
 * 更新用户组织关系
 */
export const updateUserOrganization = (data) => {
  return request({
    url: '/organization/member/update',
    method: 'put',
    data
  })
}

/**
 * 获取用户所在的所有组织
 */
export const getUserOrganizations = (userId) => {
  return request({
    url: `/organization/user/${userId}`,
    method: 'get'
  })
}

/**
 * 获取组织下所有用户ID
 */
export const getUserIdsByOrgId = (orgId, includeChildren = false) => {
  return request({
    url: `/organization/users/${orgId}`,
    method: 'get',
    params: { includeChildren }
  })
}

